<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class CrowdFundingRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'promoter' => 'required|between:1,20',
            'phone' => 'required|regex:/^1[34578][0-9]{9}$/',
            'address' => 'required|max:30',
            'wechat' => 'required|alpha_dash',
            'label' => 'required',
            'shop_type' => 'required',
            'shop_info' => 'required',
        ];
        if ($this->shop_type == 1) {
            $rules['shop_price'] = 'required|numeric|min:1500';
        } else {
            $rules['shop_price'] = 'required|numeric|min:300000';
            $rules['area'] = 'required|numeric|min:50';
        }
        return $rules;
    }

    public function messages()
    {
        $messages = [
            'promoter.required' => '发起人必填',
            'promoter.between' => '发起人姓名字符长度错误',

            'phone.required' => '手机号码必填',
            'phone.regex' => '手机号码格式错误',

            'address.required' => '店铺地址必填',
            'address.max' => '店铺地址字数过长',
            'wechat.required' => '微信号必填',
            'wechat.alpha_dash' => '微信号错误',
            'label.required' => '店铺标签必填',
            'shop_type.required' => '店铺类型必填',
            // 'label.array' => '店铺标签格式错误',

            'shop_info.required' => '店铺图片必填',
            // 'shop_info.array' => '店铺图片格式错误',

            'shop_price.required' => '拟众筹金额必填',
        ];
        if ($this->shop_type == 1) {
            $messages['shop_price.min'] = '线上众筹金额最低1500元';
        } else {
            $messages['shop_price.min'] = '线下众筹金额最低300000元';
            $messages['area.required'] = '店铺面积必填';
            $messages['area.numeric'] = '店铺面积必须为数字';
            $messages['area.min'] = '店铺面积必须最少50㎡';
        }
        return $messages;
    }

}
